local joyex__qicai = fk.CreateSkill {

  name = "joyex__qicai",

  tags = { Skill.Compulsory, },

}



joyex__qicai:addEffect(fk.BeforeCardsMove, {
  name = "joyex__qicai",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.BeforeCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(joyex__qicai.name) and (player:getEquipment(Card.SubtypeWeapon) or player:getEquipment(Card.SubtypeArmor)) then
      for _, move in ipairs(data) do
        if move.from == player and move.moveReason == fk.ReasonDiscard and (not move.proposer or move.proposer ~= player) then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerEquip and
              table.contains({Card.SubtypeWeapon, Card.SubtypeArmor}, Fk:getCardById(info.cardId).sub_type) then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local ids = {}
    for _, move in ipairs(data) do
      if move.from == player and move.moveReason == fk.ReasonDiscard and (not move.proposer or move.proposer ~= player) then
        local move_info = {}
        for _, info in ipairs(move.moveInfo) do
          local id = info.cardId
          if info.fromArea == Card.PlayerEquip and table.contains({Card.SubtypeWeapon, Card.SubtypeArmor}, Fk:getCardById(id).sub_type) then
            table.insert(ids, id)
          else
            table.insert(move_info, info)
          end
        end
        if #ids > 0 then
          move.moveInfo = move_info
        end
      end
    end
    if #ids > 0 then
      player.room:sendLog{
        type = "#cancelDismantle",
        card = ids,
        arg = joyex__qicai.name,
      }
    end
  end,
})

joyex__qicai:addEffect("targetmod", {
  name = "#joyex__qicai_targetmod",
  --joyex__qicai,
  bypass_distances = function(self, player, skill, card)
    return player:hasSkill("joyex__qicai") and card and card.type == Card.TypeTrick
  end,
})

return joyex__qicai